package com.lottery.ruok.lottrey.adapter

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.lottery.ruok.lottrey.R
import com.lottery.ruok.lottrey.bean.LHCQuickItem

class LHCQuickAmountAdapter(val items : List<LHCQuickItem>, private val itemClickListener: (String)->Unit) : RecyclerView.Adapter<LHCQuickAmountAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.lhc_quick_item_layout, parent, false)
        return ViewHolder(view, itemClickListener)
    }

    fun getLHCQuickItems(): List<LHCQuickItem> = items

    override fun getItemCount(): Int = items.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bind(items.elementAt(position))
    }

    class ViewHolder(val view: View, private val itemClickListener: (String) -> Unit) : RecyclerView.ViewHolder(view) {
        fun bind(news: LHCQuickItem) {
            view.findViewById<TextView>(R.id.option_text).text = news.number
            view.setOnClickListener {
                itemClickListener(news.number)
            }
            view.findViewById<TextView>(R.id.option_text).setBackgroundResource(if (news.isChoose) R.mipmap.mini_bing else R.mipmap.mini_bing2)
        }
    }
}